//
//  LTLastVisit.m
//  LocalTravel
//
//  Created by zheng ji on 14-2-25.
//  Copyright (c) 2014年 jxw. All rights reserved.
//

#import "LTLastVisitView.h"
#import "constants.h"

@interface LTLastVisitView ()
{
    
     UICollectionView *_collectionView;
}
@end
@implementation LTLastVisitView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
       
       [self initCollectionView];
    }
    return self;
}

-(void)initCollectionView{
       UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize=CGSizeMake(160,200);
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    
     _collectionView=[[UICollectionView alloc] initWithFrame:self.frame collectionViewLayout:flowLayout];
    
    [_collectionView registerClass:[CollectionCell class] forCellWithReuseIdentifier:@"CollectionCell"];
    
    _collectionView.delegate=self;
    _collectionView.dataSource=self;
    _collectionView.backgroundColor=[UIColor clearColor];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    if(_arrayVisits !=nil) return _arrayVisits.count;
    
    return 0;
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    CollectionCell* cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionCell" forIndexPath:indexPath];
    if(_arrayVisits !=nil && _arrayVisits.count>indexPath.row){
        NSDictionary* dict=[_arrayVisits objectAtIndex:indexPath.row];
        cell.lblTitle.text=[dict objectForKey:@"sceneryName"];
        cell.lblPrice.text=[NSString stringWithFormat:@"最低价:¥ %@",[dict objectForKey:@"amountAdv"]];

        NSString* imageName=[dict objectForKey:@"imgPath"];
        
        NSString* netImagePath=[NSString stringWithFormat:@"%@160_120/%@",[CommonConfigUtil getTongChenImageBaseUrl],imageName];
        cell.imageView.imageUrl=netImagePath;
  
    }
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if(_arrayVisits ==nil || _arrayVisits.count<indexPath.row) return ;

 
    if(delegate !=nil){
       
       [self.delegate visitDidSelection:[_arrayVisits objectAtIndex:indexPath.row]];
    }
   
}
-(void)resetFrame:(CGRect)frame{
   self.frame=frame;
   _collectionView.frame=frame;
}
-(void)setArrayVisits:(NSMutableArray*)array{
     _arrayVisits=array;

    [_collectionView reloaddata];
}
@end
